//
//  JGTDataTool.m
//  RunningMan
//
//  Created by JGT on 16/6/2.
//  Copyright © 2016年 WSJ. All rights reserved.
//

#import "JGTDataTool.h"
#import "JGTCityModel.h"
#import "JGTDaily.h"
#import "JGTHourly.h"
@implementation JGTDataTool

static JGTDataTool *_dataTool = nil;
+ (JGTDataTool *)sharedDataManager {
    if (!_dataTool) {
        _dataTool = [JGTDataTool new];
    }
    return _dataTool;
}

static NSArray *_cityGroupArray = nil;
+ (NSArray *)getAllCityGroups {
    if (!_cityGroupArray) {
        _cityGroupArray = [[self alloc] getCityGroups];
    }
    return _cityGroupArray;
}
- (NSArray *)getCityGroups {
    //读取plist文件
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"cityGroups.plist" ofType:nil];
    NSArray *cityGroupArray = [NSArray arrayWithContentsOfFile:plistPath];
    //所有字典对象转成模型对象
    NSMutableArray *mutableArray = [NSMutableArray array];
    for (NSDictionary *dic in cityGroupArray) {
        //声明一个空的TRCityGroup对象
        JGTCityModel *cityGroup = [JGTCityModel new];
        //KVC绑定模型对象属性和字典key的关系
        [cityGroup setValuesForKeysWithDictionary:dic];
        [mutableArray addObject:cityGroup];
    }
    
    return [mutableArray copy];
}

+ (NSArray *)getAllDailyData:(id)request
{
    NSArray *daily_forecast = request[@"HeWeather data service 3.0"][0][@"daily_forecast"];
    NSMutableArray *mutableArray = [NSMutableArray array];
    for (NSDictionary *dic in daily_forecast) {
        JGTDaily *daily = [JGTDaily parseDailyJson:dic];
        [mutableArray addObject:daily];
    }
    return [mutableArray copy];
}

+ (NSArray *)getAllHourlyData:(id)request
{
    NSArray *hourlyArray = request[@"HeWeather data service 3.0"][0][@"hourly_forecast"];
    NSMutableArray *mutableArray = [NSMutableArray array];
    for (NSDictionary *dic in hourlyArray) {
        JGTHourly *hourly = [JGTHourly parseHourlyJson:dic];
        [mutableArray addObject:hourly];
    }
    return [mutableArray copy];
}

+ (JGTNow *)getNowData:(id)request
{
    JGTNow *now = [JGTNow parseNowJsonData:request];
    return now;
}

@end
